package com.suyu.controller.CuitTopicController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suyu.model.entity.TopicCuit;
import com.suyu.service.TopicCuitService;
import com.suyu.util.InsertData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import net.sf.jsqlparser.statement.select.Top;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author tmh
 * @date 2023/11/4 22:11
 * @description
 */
@RestController
@RequestMapping("topic")
@Api(tags = "cuit实验操作")
public class CuitTopicController {
    @Autowired
    private TopicCuitService topicCuitService;

//    @GetMapping("/insert")
    public List<TopicCuit> insert(){
        ArrayList<TopicCuit> topicCuits = InsertData.excelToCsvAnswer();
        for (TopicCuit topicCuit : topicCuits) {
            topicCuitService.save(topicCuit);
        }
        return topicCuits;
    }

    @GetMapping("queryAnswer")
    @ApiOperation("查询实验室准入答案")
    @ApiImplicitParam(name = "topic",value = "题目描述",required = true)
    public Map<String,Object> queryAnswer(String topic){
        QueryWrapper<TopicCuit> topicCuitQueryWrapper = new QueryWrapper<TopicCuit>();
        topicCuitQueryWrapper.like("topDescription",topic);
        List<TopicCuit> list = topicCuitService.list(topicCuitQueryWrapper);
        Map<String,Object> result=new HashMap<>();
        result.put("作者","苏雨只会喵喵");
        result.put("主页地址","suyu2748.top");
        result.put("温馨提示","当全选查询不到结果的时候，建议只复制部分文字进行查询");
        result.put("查询结果",list);
        return result;
    }
}
